//
//  LGChangeTitleView.m
//  WKMaybell
//
//  Created by 何文虎 on 2019/1/15.
//  Copyright © 2019 何文虎. All rights reserved.
//

#import "LGChangeTitleView.h"

#define TITLE_WIDTH 50.f
#define TITLE_HEIGHT 20.f
#define SP_WIDTH 30.f
#define POINT_WIDTH 6.f

@interface LGChangeTitleView ()
@property(nonatomic,strong)UILabel *loginLb;
@property(nonatomic,strong)UILabel *registerLb;
@property(nonatomic,strong)UIView *loginpoint;
@property(nonatomic,strong)UIView *registerpoint;
@end

@implementation LGChangeTitleView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self setup];
    }
    return self;
}

- (void)setup{
   
    self.backgroundColor = [UIColor yellowColor];
    
    self.userInteractionEnabled = YES;
    
    [self addSubview:self.loginLb];
    self.loginLb.frame = CGRectMake(0, 0, TITLE_WIDTH, TITLE_HEIGHT);
    
    [self addSubview:self.registerLb];
    self.registerLb.frame = CGRectMake(TITLE_WIDTH+SP_WIDTH, 0, TITLE_WIDTH, TITLE_HEIGHT);
    
    [self addSubview:self.loginpoint];
    self.loginpoint.frame = CGRectMake((TITLE_WIDTH-POINT_WIDTH)/2, TITLE_HEIGHT+17, POINT_WIDTH, POINT_WIDTH);
    
    [self addSubview:self.registerpoint];
    self.registerpoint.frame = CGRectMake((TITLE_WIDTH-POINT_WIDTH)/2+TITLE_WIDTH+SP_WIDTH, TITLE_HEIGHT+17, POINT_WIDTH, POINT_WIDTH);
    
    _loginLb.font = HEBoldFont(21);
    _loginLb.textColor = UIColorFromHex(0x3C3C3C);
    
    _registerLb.font = PFSC_MediumFont(15);
    _registerLb.textColor = UIColorFromHex(0x979797);
    
    _registerpoint.hidden = YES;
    _loginpoint.hidden = YES;
    
    for (int i = 0; i<2; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(i*(self.width/2), 0, self.width/2, self.height);
        [btn addTarget:self action:@selector(changeTitleClick:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = 900+i;
        [self addSubview:btn];
    }
    
}

- (void)changeTitleClick:(UIButton*)sender{
    NSInteger index = sender.tag - 900;
   
    if (index==0) {
        dispatch_async(dispatch_get_main_queue(), ^{
            _loginLb.font = HEBoldFont(21);
            _loginLb.textColor = UIColorFromHex(0x3C3C3C);
            _registerLb.font = PFSC_MediumFont(15);
            _registerLb.textColor = UIColorFromHex(0x979797);
            _registerpoint.hidden = YES;
            _loginpoint.hidden = NO;
        });
       
    }else{
        dispatch_async(dispatch_get_main_queue(), ^{
        _registerLb.font = HEBoldFont(21);
        _registerLb.textColor = UIColorFromHex(0x3C3C3C);
        _loginLb.font = PFSC_MediumFont(15);
        _loginLb.textColor = UIColorFromHex(0x979797);
        _registerpoint.hidden = NO;
        _loginpoint.hidden = YES;
         });
    }
}

- (UILabel*)loginLb{
    if (!_loginLb) {
        _loginLb = [[UILabel alloc]init];
        _loginLb.text = @"登录";
        _loginLb.textAlignment = NSTextAlignmentCenter;
    }
    return _loginLb;
}

- (UILabel*)registerLb{
    if (!_registerLb) {
        _registerLb = [[UILabel alloc]init];
        _registerLb.text = @"注册";
        _registerLb.textAlignment = NSTextAlignmentCenter;
    }
    return _registerLb;
}

- (UIView*)loginpoint{
    if (!_loginpoint) {
        _loginpoint = [[UIView alloc]init];
        _loginpoint.backgroundColor = BACK_COLOR;
        _loginpoint.layer.masksToBounds = YES;
        _loginpoint.layer.cornerRadius = POINT_WIDTH/2;
    }
    return _loginpoint;
}

- (UIView*)registerpoint{
    if (!_registerpoint) {
        _registerpoint = [[UIView alloc]init];
        _registerpoint.backgroundColor = BACK_COLOR;
        _registerpoint.layer.masksToBounds = YES;
        _registerpoint.layer.cornerRadius = POINT_WIDTH/2;
    }
    return _registerpoint;
}

@end
